import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [{
  path: '/',
  redirect: '/login'
},
{
  path: '/init',
  name: 'Init',
  component: () => import('@/view/init/index.vue')
},
{
  path: '/login',
  name: 'Login',
  component: () => import('@/view/login/index.vue')
},
{
  path: '/:catchAll(.*)',
  meta: {
    closeTab: true,
  },
  component: () => import('@/view/error/index.vue')

}
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  methods: {
    async getData() {
      // do something
    }
  },
  beforeRouteEnter(to, from, next) {
    next(async vm => {
      vm.timer = setInterval(() => {
        vm.getData();
      }, 1 * 10000); // 1秒钟执行一次
    })
  },
  beforeRouteLeave(to, from, next) {
    clearInterval(this.timer);
    next();
  }
})
export default router
